/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tp01.utilitarios;

/**
 *
 * @author
 */
public class ByteAndConversionsUtils {

    public static byte[] concatenarArrays(byte[] a, byte[] b) {

        final int alen = a.length;
        final int blen = b.length;
        final byte[] result = (byte[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), alen + blen);
        System.arraycopy(a, 0, result, 0, alen);
        System.arraycopy(b, 0, result, alen, blen);
        return result;

    }

    public static byte[] charToByteArray(char value) {
        return new byte[]{
                    (byte) (value >>> 8),
                    (byte) value};
    }

    public static int byteArrayToChar(byte[] b) {
        return ((b[0] & 0xFF) << 8)
                + (b[1] & 0xFF);
    }
}
